package ge.telasi.tasks.ui.reporting;

import ge.telasi.tasks.ejb.TaskFacadeRemote;
import ge.telasi.tasks.ui.Platform;
import ge.telasi.tasks.ui.UIUtils;
import ge.telasi.tasks.ui.log.LoggerUtils;
import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.List;
import java.util.Map;
import javax.swing.JButton;
import javax.swing.JInternalFrame;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.JToolBar;
import javax.swing.table.DefaultTableModel;

/**
 * @author dimitri
 */
public class TaskCompReportFrame extends JInternalFrame {
    private TaskCompleteTable reportTable;
    private TaskCompReportParams parameters = new TaskCompReportParams();

    public TaskCompReportFrame() {
        initWindow();
        initComponents();
        getReport();
    }

    private void initWindow() {
        setClosable(true);
        setIconifiable(true);
        setMaximizable(true);
        setResizable(true);
        setLayout(new BorderLayout());
        setFrameIcon(UIUtils.getIcon16x16("accept.png"));
        setTitle("დავალებათა შესრულება");
        setSize(500, 400);
    }

    private void initComponents() {
        add(parameters, BorderLayout.NORTH);
        JToolBar toolbar = new JToolBar();
        toolbar.setFloatable(false);
        add(toolbar, BorderLayout.SOUTH);
        JButton btn = new JButton(UIUtils.getIcon16x16("server_go.png"));
        toolbar.add(btn);
        btn.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                getReport();
            }
        });
        // add report table
        reportTable = new TaskCompleteTable();
        add(new JScrollPane(reportTable), BorderLayout.CENTER);
    }

    private void getReport() {
        try {
            reportTable.setStartDate(parameters.getStartDate());
            reportTable.setEndDate(parameters.getEndDate());
            reportTable.refresh();
        } catch (Exception ex) {
            LoggerUtils.manageException(this, null, ex);
        }
    }

}
